/*----------------------------MegaWave2 module----------------------------*/
/* mwcommand
name = {cmviews3};
version = {"1.0"};
author = {"Baptiste Coulange"};
function = {"Cree une fmovie ou les images les trois fmovie sont l'une à coté de l'autre"};
usage = {
inG->inG		   "input image (deux fois plus grande que les autres)",
in1->in1           "input image 1 (meme dimensions)",
in2->in2           "input image 2 (meme dimensions)",
out<-out         "output Fimage"
};
*/
/*----------------------------------------------------------------------
v1.0 (04/2007): initial version
----------------------------------------------------------------------*/

#include <stdio.h>
#include <math.h>
#include "mw.h"

Fimage cmviews3(inG,in1,in2,out)
   Fmovie inG,in1,in2,out;

{
	Fimage locG,loc1,loc2,locg,prev;
	int x,y,nx,ny,ny2;
	
	ny=(in1->first)->nrow;
	nx=(in1->first)->ncol;
	out=mw_change_fmovie(out);
	locG=mw_change_fimage(NULL,2*ny+1,3*nx);
	prev=mw_change_fimage(NULL,2*ny+1,3*nx);	
	
	locg=inG->first;
	loc1=in1->first;
	loc2=in2->first;

	for(x=0;x<3*nx;x++) 
			for(y=0;y<2*ny;y++) {
				if(x<2*nx) {
				locG->gray[y*3*nx+x]=locg->gray[y*2*nx+x];
				} else {
					if(y<ny){
						locG->gray[y*3*nx+x]=loc1->gray[y*nx+(x%(2*nx))];
					} else { locG->gray[y*3*nx+x]=loc2->gray[(y%ny)*nx+(x%(2*nx))];}
				}			
			}
	out->first=locG;
	prev=locG;
	

	while(loc1->next){
		locG=mw_change_fimage(NULL,2*ny,3*nx);
		loc1=loc1->next;
		loc2=loc2->next;
		locg=locg->next;
		for(x=0;x<3*nx;x++) 
				for(y=0;y<2*ny;y++) {
					if(x<2*nx) {
					locG->gray[y*3*nx+x]=locg->gray[y*2*nx+x];
					} else {
						if(y<ny){
							locG->gray[y*3*nx+x]=loc1->gray[y*nx+(x%(2*nx))];
						} else { locG->gray[y*3*nx+x]=loc2->gray[(y%ny)*nx+(x%(2*nx))];}
					}			
				}	

		

		prev->next=locG;
		locG->previous=prev;
		prev=locG;
			
			
	}
}


